package com.gy.spark.core

import org.apache.spark.{SparkConf, SparkContext}

object Accumulator {

  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setMaster("local[*]").setAppName(Accumulator.getClass.getSimpleName)
    val sc = new SparkContext(conf)

    val acc = sc.longAccumulator("count")

    sc.textFile("words.txt").map(x => {
      acc.add(1)
      x
    }).foreach(println)

    println(s"word lines is :${acc.value}")

    sc.stop
  }

}
